From 5ca9b36a3871e8e64fed4842b3342ee74f57b76a Mon Sep 17 00:00:00 2001 From: Dirk Brenken Date: Fri, 11 Apr 2025 22:06:20 +0200 Subject: [PATCH] luci-app-banip: sync with release 1.5.6-1 * small fixes & improvements Signed-off-by: Dirk Brenken --- .../resources/view/banip/allowlist.js | 47 +++++++++++-------- .../resources/view/banip/blocklist.js | 47 +++++++++++-------- .../resources/view/banip/custom.css | 7 +++ .../luci-static/resources/view/banip/feeds.js | 9 +++- .../resources/view/banip/overview.js | 2 +- .../usr/share/luci/menu.d/luci-app-banip.json | 5 +- .../usr/share/rpcd/acl.d/luci-app-banip.json | 2 +- 7 files changed, 72 insertions(+), 47 deletions(-) diff --git a/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/allowlist.js b/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/allowlist.js index 53cc8a5607..24d9438b76 100644 --- a/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/allowlist.js +++ b/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/allowlist.js @@ -3,18 +3,41 @@ 'require fs'; 'require ui'; +let localFile = '/etc/banip/banip.allowlist'; let notMsg, errMsg; return view.extend({ load: function () { - return Promise.all([ - L.resolveDefault(fs.stat('/etc/banip/banip.allowlist'), {}), - L.resolveDefault(fs.read_direct('/etc/banip/banip.allowlist'), '') + return L.resolveDefault(fs.stat(localFile), "") + .then(function (stat) { + if (!stat) { + return fs.write(localFile, ""); + } + return Promise.all([ + L.resolveDefault(fs.stat(localFile), ""), + L.resolveDefault(fs.read_direct(localFile), "") + ]); + }); + }, + render: function (allowlist) { + if (allowlist[0].size >= 100000) { + document.body.scrollTop = document.documentElement.scrollTop = 0; + ui.addNotification(null, E('p', _('The allowlist is too big, unable to save modifications.')), 'error'); + } + return E('div', { 'class': 'cbi-section cbi-section-descr' }, [ + E('p', _('This is the local banIP allowlist that will permit certain MAC-, IP-addresses or domain names.
\ + Please note: add only exactly one MAC/IPv4/IPv6 address or domain name per line. Ranges in CIDR notation and MAC/IP-bindings are allowed.')), + E('textarea', { + 'style': 'width: 100% !important; padding: 5px; font-family: monospace; margin-top: .4em', + 'spellcheck': 'false', + 'wrap': 'off', + 'rows': 25 + }, [allowlist[1] != null ? allowlist[1] : '']) ]); }, handleSave: function (ev) { let value = ((document.querySelector('textarea').value || '').trim().toLowerCase().replace(/\r\n/g, '\n')) + '\n'; - return fs.write('/etc/banip/banip.allowlist', value) + return fs.write(localFile, value) .then(function () { document.querySelector('textarea').value = value; document.body.scrollTop = document.documentElement.scrollTop = 0; @@ -30,22 +53,6 @@ return view.extend({ } }); }, - render: function (allowlist) { - if (allowlist[0].size >= 100000) { - document.body.scrollTop = document.documentElement.scrollTop = 0; - ui.addNotification(null, E('p', _('The allowlist is too big, unable to save modifications.')), 'error'); - } - return E('div', { 'class': 'cbi-section cbi-section-descr' }, [ - E('p', _('This is the local banIP allowlist that will permit certain MAC-, IP-addresses or domain names.
\ - Please note: add only exactly one MAC/IPv4/IPv6 address or domain name per line. Ranges in CIDR notation and MAC/IP-bindings are allowed.')), - E('textarea', { - 'style': 'width: 100% !important; padding: 5px; font-family: monospace; margin-top: .4em', - 'spellcheck': 'false', - 'wrap': 'off', - 'rows': 25 - }, [allowlist[1] != null ? allowlist[1] : '']) - ]); - }, handleSaveApply: null, handleReset: null }); diff --git a/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/blocklist.js b/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/blocklist.js index b44761d32e..3a9c478da8 100644 --- a/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/blocklist.js +++ b/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/blocklist.js @@ -3,31 +3,20 @@ 'require fs'; 'require ui'; +let localFile = '/etc/banip/banip.blocklist'; let notMsg, errMsg; return view.extend({ load: function () { - return Promise.all([ - L.resolveDefault(fs.stat('/etc/banip/banip.blocklist'), {}), - L.resolveDefault(fs.read_direct('/etc/banip/banip.blocklist'), '') - ]); - }, - handleSave: function (ev) { - let value = ((document.querySelector('textarea').value || '').trim().toLowerCase().replace(/\r\n/g, '\n')) + '\n'; - return fs.write('/etc/banip/banip.blocklist', value) - .then(function () { - document.querySelector('textarea').value = value; - document.body.scrollTop = document.documentElement.scrollTop = 0; - if (!notMsg) { - ui.addNotification(null, E('p', _('Blocklist modifications have been saved, reload banIP that changes take effect.')), 'info'); - notMsg = true; - } - }).catch(function (e) { - document.body.scrollTop = document.documentElement.scrollTop = 0; - if (!errMsg) { - ui.addNotification(null, E('p', _('Unable to save modifications: %s').format(e.message)), 'error'); - errMsg = true; + return L.resolveDefault(fs.stat(localFile), "") + .then(function (stat) { + if (!stat) { + return fs.write(localFile, ""); } + return Promise.all([ + L.resolveDefault(fs.stat(localFile), ""), + L.resolveDefault(fs.read_direct(localFile), "") + ]); }); }, render: function (blocklist) { @@ -46,6 +35,24 @@ return view.extend({ }, [blocklist[1] != null ? blocklist[1] : '']) ]); }, + handleSave: function (ev) { + let value = ((document.querySelector('textarea').value || '').trim().toLowerCase().replace(/\r\n/g, '\n')) + '\n'; + return fs.write(localFile, value) + .then(function () { + document.querySelector('textarea').value = value; + document.body.scrollTop = document.documentElement.scrollTop = 0; + if (!notMsg) { + ui.addNotification(null, E('p', _('Blocklist modifications have been saved, reload banIP that changes take effect.')), 'info'); + notMsg = true; + } + }).catch(function (e) { + document.body.scrollTop = document.documentElement.scrollTop = 0; + if (!errMsg) { + ui.addNotification(null, E('p', _('Unable to save modifications: %s').format(e.message)), 'error'); + errMsg = true; + } + }); + }, handleSaveApply: null, handleReset: null }); diff --git a/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/custom.css b/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/custom.css index 23c60c683d..d79e6f987b 100644 --- a/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/custom.css +++ b/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/custom.css @@ -1,3 +1,10 @@ .cbi-input-text { width: 90% !important; + margin-bottom: -5px; + padding-top: 0rem; } + +.cbi-input-select { + margin-bottom: -5px; + padding-top: 0rem; +} \ No newline at end of file diff --git a/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/feeds.js b/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/feeds.js index b1c4d915ca..4fe01adf4a 100644 --- a/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/feeds.js +++ b/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/feeds.js @@ -168,7 +168,13 @@ function handleEdit(ev) { return view.extend({ load: function () { - return L.resolveDefault(fs.read_direct('/etc/banip/banip.custom.feeds', 'json'), ""); + return L.resolveDefault(fs.stat('/etc/banip/banip.custom.feeds'), "") + .then(function (stat) { + if (!stat) { + return fs.write('/etc/banip/banip.custom.feeds', ""); + } + return L.resolveDefault(fs.read_direct('/etc/banip/banip.custom.feeds', 'json'), ""); + }) }, render: function (data) { @@ -243,6 +249,7 @@ return view.extend({ o = s.option(form.ListValue, 'rule_6', _('Rulev6')); o.value('/^(([0-9A-f]{0,4}:){1,7}[0-9A-f]{0,4}:?(\\/(1?[0-2][0-8]|[0-9][0-9]))?)[[:space:]]/{printf \"%s,\\n\",$1}', _('')); o.value('/^(([0-9A-f]{0,4}:){1,7}[0-9A-f]{0,4}:?(\\/(1?[0-2][0-8]|[0-9][0-9]))?)$/{printf \"%s,\\n\",$1}', _('')); + o.value('BEGIN{FS=\",\"}/^(([0-9A-f]{0,4}:){1,7}[0-9A-f]{0,4}:?(\\/(1?[0-2][0-8]|[0-9][0-9]))?)/{printf \"%s,\\n\",$1}', _(', csv')); o.optional = true; o.rmempty = true; diff --git a/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/overview.js b/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/overview.js index 35a258a5b1..09ccb231c4 100644 --- a/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/overview.js +++ b/applications/luci-app-banip/htdocs/luci-static/resources/view/banip/overview.js @@ -18,7 +18,7 @@ function handleAction(ev) { .then(L.bind(ui.changes.apply, ui.changes)) .then(function () { return fs.exec_direct('/etc/init.d/banip', [ev]); - }); + }) } else { return fs.exec_direct('/etc/init.d/banip', [ev]); } diff --git a/applications/luci-app-banip/root/usr/share/luci/menu.d/luci-app-banip.json b/applications/luci-app-banip/root/usr/share/luci/menu.d/luci-app-banip.json index 9d3ebdc483..642bdcefa9 100644 --- a/applications/luci-app-banip/root/usr/share/luci/menu.d/luci-app-banip.json +++ b/applications/luci-app-banip/root/usr/share/luci/menu.d/luci-app-banip.json @@ -14,9 +14,6 @@ "/usr/bin/banip-service.sh": "executable", "/etc/init.d/banip": "executable", "/etc/banip/banip.feeds": "file", - "/etc/banip/banip.custom.feeds": "file", - "/etc/banip/banip.allowlist": "file", - "/etc/banip/banip.blocklist": "file", "/etc/banip/banip.countries": "file" }, "uci": { @@ -80,4 +77,4 @@ "path": "banip/processing_log" } } -} +} \ No newline at end of file diff --git a/applications/luci-app-banip/root/usr/share/rpcd/acl.d/luci-app-banip.json b/applications/luci-app-banip/root/usr/share/rpcd/acl.d/luci-app-banip.json index a572c77621..56bbcc3758 100644 --- a/applications/luci-app-banip/root/usr/share/rpcd/acl.d/luci-app-banip.json +++ b/applications/luci-app-banip/root/usr/share/rpcd/acl.d/luci-app-banip.json @@ -72,4 +72,4 @@ ] } } -} +} \ No newline at end of file -- 2.30.2